package liportest.Entity;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.omg.CORBA.UNKNOWN;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * Created by lipor
 * Date 2020/7/22
 */
@Getter
@AllArgsConstructor
public enum EventEnum {
    VIEW_TIME(0, "视频时长"),
    START_TIME(1, "开始时间"),
    END_TIME(2, "结束时间"),
    UPLOAD_STATUS(3, "上传结果"),
    UNKNOWN(99, "未知");
    private Integer code;
    private String describe;

    public static Map<Integer, EventEnum> CODE_MAP = new HashMap<>();

    static {
        for (EventEnum e : EventEnum.values()) {
            CODE_MAP.put(e.code, e);
        }
    }

    public static EventEnum getEnum(Integer code) {
        return CODE_MAP.get(code);
    }


    public static EventEnum getEnumByCode(Integer code) {
        for (EventEnum e : values()) {
            if (Objects.equals(e.getCode(), code)) {
                return e;
            }
        }
        return UNKNOWN;
    }
}
